/*
 * ******************************************************************************
 *   Copyright © 2013-2014 sean.yanghy. All rights reserved.
 *
 *  *****************************************************************************
 */

package com.exteam.common.network;

/**
 * @author sean.yanghy
 * @version v1.0
 * @created 2014-07-06 13:56:23
 */
public interface IRequest {

    public static final String METHOD_GET = "GET";
    public static final String METHOD_POST = "POST";

    public void request(HttpIntent httpIntent, IRequestCallBack callBack);

    public void requestByPost(HttpIntent i, final IRequestCallBack callBack);

//	public <T> T parse(T dataObject);

    /**
     * 获得接口未解析时的数据String
     *
     * @return
     */
    public String getDataString();

    public void cancel();

    public boolean isCancel();

    public abstract class IRequestCallBack {

        public abstract void onSuccess(RequestManager request);

        public abstract void onFailed(String failReason);

        private RequestManager m;

        public final void setHttpRequestManager(RequestManager m) {
            this.m = m;
        }

        public final void localLoad() {
            onLocalLoad(m);
        }

        /**
         * 本地加载(当无网络时会自动执行，若手动执行请使用IHttpRequestCallBack{@link #localLoad()})
         */
        public void onLocalLoad(IRequest request) {
            onSuccess((RequestManager) request);
        }

        // public void onCancel();
    }

}
